﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamSystem.BLL;
using ExamSystem.Mdeol;
namespace ExamSystem.ht
{
    public partial class TStudent_List : System.Web.UI.Page
    {
        private TstudentBLL td = new TstudentBLL();
        private TclassBLL tb = new TclassBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    string tcid = Request.QueryString["id"];
                    if (!string.IsNullOrEmpty(tcid))
                    {
                        td.delete(int.Parse(tcid));
                        util.FunHelper.LayerAlter(this, "删除成功", "TStudent_List.aspx");
                    }
                }
                catch
                {
                    util.FunHelper.LayerAlter(this, "删除失败", "TStudent_List.aspx");
                }


                List<Tclass> list = tb.selecttclass();
                Tclass bi = new Tclass(0, "全部");
                list.Insert(0, bi);

                this.tcId.DataSource = list;
                this.tcId.DataTextField = "tcno";
                this.tcId.DataValueField = "tcid";
                this.tcId.DataBind();

                this.mohu();
            }
        }

        private void mohu()
        {
            string name = this.tsName.Value;
            int tcid = int.Parse(this.tcId.Value);
            List<Tstudent> list = td.selecttstudent(tcid,name);
            this.lbTotal.InnerText = list.Count + "";
            //分页类
            PagedDataSource page = new PagedDataSource();
            //属性
            page.AllowPaging = true;
            page.PageSize = 5;
            page.CurrentPageIndex = int.Parse(this.pageNo.Value) - 1;
            page.DataSource = list;


            //绑定数据源
            this.Repeater1.DataSource = page;
            //绑定数据
            this.Repeater1.DataBind();


            //当前几页总共几页
            this.lbPageCount.InnerText = this.pageNo.Value;
            this.lbPageNo.InnerText = page.PageCount + "";

            //规避按钮
            if (page.IsFirstPage)
            {
                this.btnFirst.Enabled = false;
                this.btnUp.Enabled = false;
            }
            else
            {
                this.btnFirst.Enabled = true; ;
                this.btnUp.Enabled = true; ;
            }


            if (page.IsLastPage)
            {
                this.btnLast.Enabled = false;
                this.btnDown.Enabled = false;
            }
            else
            {
                this.btnLast.Enabled = true;
                this.btnDown.Enabled = true;
            }
        }


        //查询
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.mohu();
        }
        //第一页
        protected void btnFirst_Click(object sender, EventArgs e)
        {
            this.pageNo.Value = "1";
            this.mohu();
        }
        //上一页
        protected void btnUp_Click(object sender, EventArgs e)
        {
            int pageno = int.Parse(this.pageNo.Value);
            pageno--;
            this.pageNo.Value = pageno + "";
            this.mohu();
        }
        //下一页
        protected void btnDown_Click(object sender, EventArgs e)
        {
            int pageno = int.Parse(this.pageNo.Value);
            pageno++;
            this.pageNo.Value = pageno + "";
            this.mohu();
        }
        //尾页
        protected void btnLast_Click(object sender, EventArgs e)
        {
            this.pageNo.Value = this.lbPageNo.InnerText;
            this.mohu();
        }
    }
}